<script setup lang="ts">
import {useMessage, useNotification} from "naive-ui"
import {watch} from "vue"
import {useTipStore} from "./stores/tip-store.ts"
import {TipMessageTypeConst, TipNotificationTypeConst} from './const/tip-const.ts'

// 提示状态存储仓库
const tipStore = useTipStore()

/**
 * 组件配置选项
 */
defineOptions({
  name: 'StnTip'
})

// 信息提示对象
const message = useMessage()
/**
 * 监听提示状态变化，并根据提示类型显示对应的提示信息
 */
watch(() => tipStore.getMessageStatus(), () => {
  switch (tipStore.getMessageType()) {
    case TipMessageTypeConst.SUCCESS:
      message.success(tipStore.getMessageContent())
      break
    case TipMessageTypeConst.ERROR:
      message.error(tipStore.getMessageContent())
      break
    case TipMessageTypeConst.WARNING:
      message.warning(tipStore.getMessageContent())
      break
    case TipMessageTypeConst.INFO:
      message.info(tipStore.getMessageContent())
      break
    case TipMessageTypeConst.LOADING:
      message.loading(tipStore.getMessageContent())
      break
  }
})

// 通知提示对象
const notification = useNotification()
/**
 * 监听提示状态变化，并根据提示类型显示对应的提示信息
 */
watch(() => tipStore.getNotificationStatus(), () => {
  switch (tipStore.getNotificationType()) {
    case TipNotificationTypeConst.SUCCESS:
      notification.success(tipStore.getNotificationOptions())
      break
    case TipNotificationTypeConst.ERROR:
      notification.error(tipStore.getNotificationOptions())
      break
    case TipNotificationTypeConst.WARNING:
      notification.warning(tipStore.getNotificationOptions())
      break
    case TipNotificationTypeConst.INFO:
      notification.info(tipStore.getNotificationOptions())
      break
  }
})
</script>

<template></template>

<style scoped></style>
